<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        width: 3.45rem;
        height: 1.5rem;
        margin: 0.15rem;
        background-color: skyblue;
        box-sizing: border-box;
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <div class="box"></div>
    <script>
      // 1. rem适配
      document.documentElement.style.fontSize =
        (document.documentElement.clientWidth * 100) / 375 + 'px'

      // 2. 1px 不参与适配

      // 3. 要让布局视口等比变大.如果像素比为2. 则变大2倍. 像素比为3.则变大3倍
      // meta标签中的width和initial-scale如何计算的布局视口不同,则大的值生效
      // 让布局视口变大的原理: 修改initial-scale的值让布局视口变大

      // 计算initial-scale的值
      const scale = 1 / window.devicePixelRatio
      // 获取开启理想视口的meta标签
      const viewport = document.querySelector('meta[name=viewport]')
      // console.log(viewport)
      viewport.content = `width=device-width, initial-scale=${scale}`
      //4. 让根标签的字体大小,等比变大.像素比为2.变大2倍.像素比为3,变大3倍
      document.documentElement.style.fontSize =
        parseFloat(document.documentElement.style.fontSize) *
          window.devicePixelRatio +
        'px'
    </script>
  </body>
</html>
